﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClientAppViaWebService.OrganizationalDivisionsLogicServiceRef;

namespace ClientAppViaWebService.Forms
{
    public partial class OrganizationalDivisionEditForm : DivisionEditForm
    {
        private readonly Int32 ClassID = 11;
        private OrganizationalDivisionsLogicService orgDivService;

        #region Properties.

        public string Slogan
        {
            get { return txtSlogan.Text; }
            set { txtSlogan.Text = value; }
        }
       
        public String Email
        {
            get { return txtEmail.Text; }
            set { txtEmail.Text = value; }
        }       

        #endregion

        public OrganizationalDivisionEditForm()
        {
            InitializeComponent();
            orgDivService = new  OrganizationalDivisionsLogicService();
        }

        protected override void SetFormProperties(Object _object)
        {
            OrganizationalDivision obj = (_object as OrganizationalDivision);
            ID = obj.ID;
            EXT_ID = obj.EXT_ID;
            ParentId = obj.PARENT_ID;
            Class = obj.CLASS_ID;
            ObjName = obj.NAME;
            BossName = obj.BOSS_ID;
            DateCreated = obj.DATE_CREATED;
            Description = obj.DESCRIPTION;
            Slogan  = obj.SLOGAN;
            Email= obj.EMAIL;
        }

        protected override Object RetrieveFormProperties()
        {
            OrganizationalDivision obj = new OrganizationalDivision();
            obj.ID = ID;
            obj.EXT_ID = EXT_ID;
            obj.PARENT_ID = ParentId;
            obj.CLASS_ID = ClassID;
            obj.NAME = ObjName;
            obj.DataBaseName = DataBaseName;
            obj.BOSS_ID = BossName;
            obj.DATE_CREATED = DateCreated;
            obj.DESCRIPTION = Description;
            obj.SLOGAN  = Slogan;
            obj.EMAIL= Email;
            return obj;
        }

        protected override void LoadEditFormData(int parentNodeID)
        {
            OrganizationalDivision p = orgDivService.SelectOrganizationalDivision_By_DataBase_And_Id(DataBaseName, parentNodeID);
            SetFormProperties(p);
        }

        protected override void UpdateEntity()
        {
            OrganizationalDivision obj = RetrieveFormProperties() as OrganizationalDivision;
           orgDivService.UpdateOrganizationalDivision(obj);
        }

        protected override void InsertEntity()
        {
            OrganizationalDivision obj = RetrieveFormProperties() as OrganizationalDivision;
            orgDivService.InsertOrganizationalDivision(obj);
        }
    }
}
